
/**
 *渐变光圈纹理
 * @param {}color 颜色
 * @param {}rate 速率
 * @param {}repeatNum 重复数量
 */
function CesiumGradualLightRingMaterialProperty(options) {
  this._definitionChanged = new Cesium.Event();
  this.color = options.color;
  this.rate = options.rate;
  this.repeatNum = options.repeatNum;
}
CesiumGradualLightRingMaterialProperty.prototype.getType = function (time) {
  return "CesiumGradualLightRingMaterialProperty";
};
CesiumGradualLightRingMaterialProperty.prototype.getValue = function (
  time,
  result
) {
  if (!Cesium.defined(result)) {
    result = {};
  }
  result.color = Cesium.Property.getValueOrClonedDefault(
    this.color,
    time,
    new Cesium.Color(0.23, 0.67, 0.9, 1.0),
    result.color
  );
  result.rate = Cesium.Property.getValueOrClonedDefault(
    this.rate,
    time,
    1,
    result.rate
  );
  result.repeatNum = Cesium.Property.getValueOrClonedDefault(
    this.repeatNum,
    time,
    5,
    result.repeatNum
  );
  return result;
};
CesiumGradualLightRingMaterialProperty.prototype.equals = function (other) {
  return (
    this === other ||
    (other instanceof CesiumGradualLightRingMaterialProperty &&
      Cesium.Property.equals(this.color, other.color) &&
      Cesium.Property.equals(this.rate, other.rate) &&
      Cesium.Property.equals(this.repeatNum, other.repeatNum))
  );
};
Object.defineProperties(CesiumGradualLightRingMaterialProperty.prototype, {
  isConstant: {
    get: function () {
      return false;
    },
  },
  definitionChanged: {
    get: function () {
      return this._definitionChanged;
    },
  },
  color: Cesium.createPropertyDescriptor("color"),
  rate: Cesium.createPropertyDescriptor("rate"),
  repeatNum: Cesium.createPropertyDescriptor("repeatNum"),
});
Cesium.CesiumGradualLightRingMaterialProperty =
  CesiumGradualLightRingMaterialProperty;
Cesium.Material.CesiumGradualLightRingMaterialPropertyType =
  "CesiumGradualLightRingMaterialProperty";
Cesium.Material.CesiumGradualLightRingMaterialPropertyMaterialSource = `
                  float iTime= czm_frameNumber/ 100.0;
                  float pointy (float f) {
                      // return 0.2/(abs(f)+0.2);
                      return 0.01/(abs(f)+0.02);
                  }
                  czm_material czm_getMaterial(czm_materialInput materialInput)
                  {
                      czm_material material = czm_getDefaultMaterial(materialInput);
                      vec2 str = materialInput.st*1.0;
                      //----------------------------------------------------------
                      vec2 uv = str;
                      uv.y=fract(uv.y*repeatNum);
                      vec3 col001 = vec3(0.0);
                      float f001 =fract( abs(uv.y - (iTime*0.5*rate)));
                      col001 = vec3(pointy(f001));
                  
                      // vec3 col= vec3(0.93, 0.97, 1) -  vec3(0.7, 0.3, 0.1);//颜色2
                      vec3 col= color.rgb;//颜色2
                      material.diffuse =  col*(1.0-str.y)*(1.0-str.y)*(1.0-str.y)*(1.0-str.y)+col001;
                      material.emission =  col+col001;
                      material.alpha = (1.0-str.y);
                      return material;
                      }`;
Cesium.Material._materialCache.addMaterial(
  Cesium.Material.CesiumGradualLightRingMaterialPropertyType,
  {
    fabric: {
      type: Cesium.Material.CesiumGradualLightRingMaterialPropertyType,
      uniforms: {
        color: new Cesium.Color(0.23, 0.67, 0.9, 1.0),
        rate: 1,
        repeatNum: 5,
      },
      source:
        Cesium.Material.CesiumGradualLightRingMaterialPropertyMaterialSource,
    },
    translucent: function (material) {
      return true;
    },
  }
);

export default CesiumGradualLightRingMaterialProperty;
